<template>
  <div class="cart">
    
    <div class="content">
      <div class="step-box">
        <div class="left">
          <span class="img"></span>
          <span class="text">{{$t('cart.cart')}}</span>
        </div>
        <div class="steps">
          <div class="item active">
            <div class="number">step 01.</div>
            <div class="text">{{$t('cart.selectProductToBuy')}}</div>
          </div>
          <div class="item">
            <div class="number">step 02.</div>
            <div class="text">{{$t('cart.confirmOrderInformation')}}</div>
          </div>
          <div class="item">
            <div class="number">step 03.</div>
            <div class="text">{{$t('cart.payToCompleteTheOrder')}}</div>
          </div>
        </div>
      </div>
      <div class="cart-tab">
        <div class="tab-check">
          <input
            type="checkbox"
            class="checkbox default"
            :class="{ checked: allChecked, default: !allChecked }"
            @click="checkAll()"
          />
          <span class="text">{{$t('all')}}</span>
        </div>
        <div class="tab-img">&nbsp;</div>
        <div class="tab-name">{{$t('products')}}</div>
        <div class="tab-price">{{$t('priceOne')}}</div>
        <div class="tab-number">{{$t('quantity')}}</div>
        <div class="tab-total">{{$t('subtotal')}}</div>
        <div class="tab-action">{{$t('operation')}}</div>
      </div>
      <div class="empty" v-if="!shopCatList.length">
        <div class="img">
          <img src="~/assets/images/emptyPic/cart-empty.png" alt />
        </div>
        <div class="action">
          <div class="text">{{$t('cart.yourShoppingCartIsEmpty')}}</div>
          <nuxt-link :to="'/'" class="btn">{{$t('cart.goShopping')}}</nuxt-link>
        </div>
      </div>
      <div v-for="(shopCat, index) in shopCatList" :key="index">
        <div class="cart-con">
          <div class="shop-box">
            <div class="shop-msg">
              <input
                type="checkbox"
                class="checkbox default"
                :class="{ checked: shopCat.checked, default: !shopCat.checked }"
                @click="checkShop(index)"
              />
              <span class="self" v-if="shopCat.shopId === 1">{{$t('prodDetail.selfEmployed')}}</span>
              <a :href="'shopIndex?sid=' + shopCat.shopId" class="shop-name">{{
                shopCat.shopName
              }}</a>
            </div>
          </div>
          <div class="activity-list">
            <div
              class="cart-con"
              v-for="(shopCartItem,
              shopCartItemIndex) in shopCat.shopCartItemDiscounts"
              :key="shopCartItemIndex"
            >
              <div class="activity-list">
                <div
                  class="activity-msg"
                  v-if="shopCartItem.chooseDiscountItemDto"
                >
                  <div class="a-info">
                    <div class="icon">
                      {{
                         [$t('cart.fullReduction'), $t('cart.fullPieceDiscount'), $t('cart.fullDiscount'), $t('cart.discountOnFullPieces')][
                          shopCartItem.chooseDiscountItemDto.discountRule
                        ]
                      }}
                    </div>
                    <div
                      class="text"
                      v-if="
                        shopCartItem.chooseDiscountItemDto.discountRule == 0
                      "
                    >
                      <span
                        v-if="shopCartItem.chooseDiscountItemDto.reduceAmount"
                      >
                        {{$t('cart.activeItemsAreFullyPurchased')}}￥{{
                          parsePrice(
                            shopCartItem.chooseDiscountItemDto.needAmount
                          )[0]
                        }}.{{
                          parsePrice(
                            shopCartItem.chooseDiscountItemDto.needAmount
                          )[1]
                        }}（
                        <span class="text-red"
                          >{{$t('cart.reduced')}}￥{{
                            parsePrice(
                              shopCartItem.chooseDiscountItemDto.reduceAmount
                            )[0]
                          }}.{{
                            parsePrice(
                              shopCartItem.chooseDiscountItemDto.reduceAmount
                            )[1]
                          }}</span
                        >）
                      </span>
                      <span v-else style="color:#999"
                        >{{$t('cart.activeItemsPurchasedOver')}}￥{{
                          parsePrice(
                            shopCartItem.chooseDiscountItemDto.needAmount
                          )[0]
                        }}.{{
                          parsePrice(
                            shopCartItem.chooseDiscountItemDto.needAmount
                          )[1]
                        }}
                        {{$t('cart.getAFullDiscount')}}</span
                      >
                    </div>
                    <div
                      class="text"
                      v-if="
                        shopCartItem.chooseDiscountItemDto.discountRule == 1
                      "
                    >
                      <span
                        v-if="shopCartItem.chooseDiscountItemDto.reduceAmount"
                      >
                        {{$t('cart.activeItemsAreFullyPurchased')}}
                        {{ shopCartItem.chooseDiscountItemDto.needAmount }}件{{$t('items')}}（
                        <span class="text-red"
                          >{{$t('cart.reduced')}}￥{{
                            parsePrice(
                              shopCartItem.chooseDiscountItemDto.reduceAmount
                            )[0]
                          }}.{{
                            parsePrice(
                              shopCartItem.chooseDiscountItemDto.reduceAmount
                            )[1]
                          }}</span
                        >）
                      </span>
                      <span v-else style="color:#999"
                        >{{$t('cart.activeItemsPurchasedOver')}}
                        {{ shopCartItem.chooseDiscountItemDto.needAmount }}
                        {{$t('items')}}{{$t('cart.getAFullDiscount')}}</span
                      >
                    </div>
                    <div
                      class="text"
                      v-if="
                        shopCartItem.chooseDiscountItemDto.discountRule == 2
                      "
                    >
                      <span
                        v-if="shopCartItem.chooseDiscountItemDto.reduceAmount"
                      >
                        {{$t('cart.activeItemsAreFullyPurchased')}}￥{{
                          parsePrice(
                            shopCartItem.chooseDiscountItemDto.needAmount
                          )[0]
                        }}.{{
                          parsePrice(
                            shopCartItem.chooseDiscountItemDto.needAmount
                          )[1]
                        }}（
                        <span class="text-red"
                          >{{$t('cart.reduced')}}￥{{
                            parsePrice(
                              shopCartItem.chooseDiscountItemDto.reduceAmount
                            )[0]
                          }}.{{
                            parsePrice(
                              shopCartItem.chooseDiscountItemDto.reduceAmount
                            )[1]
                          }}</span
                        >）
                      </span>
                      <span v-else style="color:#999"
                        >{{$t('cart.activeItemsPurchasedOver')}}￥{{
                          parsePrice(
                            shopCartItem.chooseDiscountItemDto.needAmount
                          )[0]
                        }}.{{
                          parsePrice(
                            shopCartItem.chooseDiscountItemDto.needAmount
                          )[1]
                        }}
                        {{$t('cart.enjoyAFullDiscount')}}</span
                      >
                    </div>
                    <div
                      class="text"
                      v-if="
                        shopCartItem.chooseDiscountItemDto.discountRule == 3
                      "
                    >
                      <span
                        v-if="shopCartItem.chooseDiscountItemDto.reduceAmount"
                      >
                        {{$t('cart.activeItemsAreFullyPurchased')}}
                        {{ shopCartItem.chooseDiscountItemDto.needAmount }}{{$t('items')}}（
                        <span class="text-red"
                          >{{$t('cart.reduced')}}￥{{
                            parsePrice(
                              shopCartItem.chooseDiscountItemDto.reduceAmount
                            )[0]
                          }}.{{
                            parsePrice(
                              shopCartItem.chooseDiscountItemDto.reduceAmount
                            )[1]
                          }}</span
                        >）
                      </span>
                      <span v-else style="color:#999"
                        >{{$t('cart.activeItemsPurchasedOver')}}
                        {{ shopCartItem.chooseDiscountItemDto.needAmount }}
                        {{$t('cart.items')}} {{$t('cart.enjoyAFullDiscount')}}</span
                      >
                    </div>
                    <nuxt-link
                      :to="
                        '/discount-detail?discountId=' +
                          shopCartItem.chooseDiscountItemDto.discountId
                      "
                      class="link"
                    >
                      {{
                        shopCartItem.chooseDiscountItemDto.reduceAmount
                          ? $t('cart.goToAdd')
                          : $t('cart.goToTheList')
                      }}
                      <span class="arr">>></span>
                    </nuxt-link>
                  </div>
                  <div class="a-price">
                    <!-- <div class="total">
                      <span>￥{{parsePrice(shopCartItem.checkedGoodsTotal)[0]}}.{{parsePrice(shopCartItem.checkedGoodsTotal)[1]}}</span>
                    </div>-->
                    <div class="discount">
                      <span
                        v-if="shopCartItem.chooseDiscountItemDto.reduceAmount"
                        >-￥{{
                          parsePrice(
                            shopCartItem.chooseDiscountItemDto.reduceAmount
                          )[0]
                        }}.{{
                          parsePrice(
                            shopCartItem.chooseDiscountItemDto.reduceAmount
                          )[1]
                        }}</span
                      >
                    </div>
                  </div>
                </div>
                <div class="activity-goods">
                  <div
                    :class="[
                      item.checked ? 'active item' : 'item',
                      item.discountId > 0 && shopCartItem.chooseDiscountItemDto ? 'activity-goods-checked' : ''
                    ]"
                    v-for="(item, itemIndex) in shopCartItem.shopCartItems"
                    :key="itemIndex"
                  >
                    <div class="tab-check">
                      <input
                        type="checkbox"
                        class="checkbox"
                        checkbox
                        :class="{
                          checked: item.checked,
                          default: !item.checked
                        }"
                        @click="checkOne(index, shopCartItemIndex, itemIndex)"
                      />
                    </div>
                    <div class="tab-img">
                      <a :href="'/detail/' + item.prodId" class="img-box">
                        <img :src="item.pic" alt />
                      </a>
                    </div>
                    <div class="tab-name">
                      <a :href="'/detail/' + item.prodId" class="name">{{
                        item.prodName
                      }}</a>
                      <span class="sku">{{ item.skuName }}</span>
                    </div>
                    <div class="tab-price">
                      <div class="unit-price">
                        ￥{{ parsePrice(item.price)[0] }}.{{
                          parsePrice(item.price)[1]
                        }}
                      </div>
                      <div class="promotion-box">
                        <div
                          class="p-tit"
                          v-if="item.discountId > 0 || item.discountId == -1"
                          :data-basketid="item.basketId"
                          @click.prevent="onShowDisList(item.basketId)"
                        >
                          {{$t('promotion')}}
                        </div>
                        <transition name="fade">
                          <div
                            class="p-con"
                            v-if="
                              showDiscountsList &&
                                item.basketId == currentBasketId
                            "
                          >
                            <div class="p-items-con">
                              <div
                              class="p-item"
                              v-for="(discountItem, index) in item.discounts"
                              :key="discountItem.discountId"
                            >
                              <input
                                @change="
                                  onChooseDiscount(
                                    discountItem.discountId,
                                    item.basketId
                                  )
                                "
                                :id="index"
                                type="radio"
                                class="radio"
                                :name="item.prodId"
                                :checked="
                                  discountItem.discountId == item.discountId
                                "
                              />
                              <label :for="index" class="p-info">{{
                                discountItem.discountName
                              }}</label>
                            </div>
                            <div class="p-item">
                              <input
                                @change="onChooseDiscount(-1, item.basketId)"
                                id="nodiscount"
                                type="radio"
                                class="radio"
                                :name="item.prodId"
                                :checked="item.discountId == -1"
                              />
                              <label for="nodiscount" class="p-info"
                                >{{$t('cart.noEventDiscount')}}</label
                              >
                            </div>
                            </div>
                            <div class="p-btns">
                              <a
                                href="javascript:void(0)"
                                class="sure"
                                @click="submitDiscount"
                                >{{$t('determine')}}</a
                              >
                              <a
                                href="javascript:void(0)"
                                class="cancel"
                                @click="showDiscountsList = false"
                                >{{$t('cancel')}}</a
                              >
                            </div>
                          </div>
                        </transition>
                      </div>
                    </div>
                    <div class="tab-number">
                      <div class="goods-number">
                        <span
                          class="reduce"
                          :class="{ limit: item.prodCount === 1 }"
                          @click="subCount(index, shopCartItemIndex, itemIndex)"
                          >-</span
                        >
                        <input
                          type="text"
                          class="number"
                          v-model="item.prodCount"
                          readonly="true"
                        />
                        <span
                          class="increase"
                          @click="addCount(index, shopCartItemIndex, itemIndex)"
                          >+</span
                        >
                      </div>
                    </div>
                    <!-- <div class="tab-total">￥{{parsePrice(item.productTotalAmount)[0]}}.{{parsePrice(item.productTotalAmount)[1]}}</div> -->
                    <div class="tab-total">
                      ￥{{ parsePrice(item.prodCount * item.price)[0] }}.{{
                        parsePrice(item.prodCount * item.price)[1]
                      }}
                    </div>
                    <div class="tab-action">
                      <!-- <a
                        href="JavaScript:;"
                        class="action-a collect"
                        @click="collection(index, shopCartItemIndex, itemIndex)"
                        >{{ item.isCollection ? '取消收藏' : '移入收藏夹' }}</a
                      > -->
                      <a
                        href="JavaScript:;"
                        class="action-a collect"
                        :style="$t('language')=='en'?moveToFavorites:''"
                        @click="collection(index, shopCartItemIndex, itemIndex)"
                        >{{$t('cart.moveToFavorites')}}</a
                      >
                      <a
                        href="JavaScript:;"
                        class="action-a del"
                        @click="openPopup(item.basketId)"
                        >{{$t('delete')}}</a
                      >
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div class="cart-bottom" v-if="shopCatList.length">
        <div class="total-box">
          <div class="check-all">
            <input
              type="checkbox"
              class="checkbox"
              :class="{ checked: allChecked, default: !allChecked }"
              @click="checkAll()"
            />
            <span class="text" @click="checkAll()">{{$t('cart.selectAll')}}</span>
          </div>
          <a href="JavaScript:;" class="del-selected" @click="openPopup()"
            >{{$t('cart.deleteSelectedProducts')}}</a
          >
        </div>
        <div class="settlement-box">
          <div class="amount">
            {{$t('cart.selected')}}
            <span class="number">{{ this.count }}</span
            >{{$t('cart.itemsProducts')}}
          </div>
          <div class="price-box">
            <div class="total-price">
              {{$t('cart.totalPrice')}}：
              <span class="text"
                >¥{{ parsePrice(this.finalMoney)[0] }}.{{
                  parsePrice(this.finalMoney)[1]
                }}</span
              >
            </div>
            <div class="discount-price">
              {{$t('cart.offers')}}：
              <span class="text"
                >-¥{{ parsePrice(this.subtractMoney)[0] }}.{{
                  parsePrice(this.subtractMoney)[1]
                }}</span
              >
            </div>
          </div>
          <a href="JavaScript:;" class="btn" @click="submit()" :style="{fontSize:$t('language')=='en'?'14px':'16px'}">{{$t('cart.goToSettlement')}}</a>
        </div>
      </div>
      <div class="popup-mask" v-if="isPopup"></div>
      <!-- 删除提示弹窗 -->
      <div class="popup-box" v-if="isPopup">
        <div class="tit">
          <div class="text">{{$t('tips')}}</div>
          <div class="close" @click="closePopup()"></div>
        </div>
        <div class="con">
          <div class="tip">
            <div class="tip-icon warning"></div>
            <div class="tip-info">
              <div class="result">{{$t('cart.deleteThisItem')}}</div>
              <div class="date">{{$t('cart.removeCart')}}</div>
              <div class="btns">
                <a href="JavaScript:;" class="btn-r" @click="remove()">{{$t('delete')}}</a>
                <a href="JavaScript:;" class="btn-g" @click="closePopup()"
                  >{{$t('cancel')}}</a
                >
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { _debounce } from "~/plugins/util";   //防抖
import util from '~/plugins/util'
export default {
  data () {
    return {
      shopCatList: [],
      allChecked: true,
      count: 0,
      finalMoney: 0,
      subtractMoney: 0,
      totalMoney: 0,
      isPopup: false,
      basketId: null,

      showDiscountsList: false, // 促销活动显隐
      currentBasketId: '',
      discountData: {},
      reqData: [],
      moveToFavorites:{
        position: "relative",
        left: "-25px"
      }
    }
  },
  mounted () {
    // 设置网页标题
    document.title = this.$t('cart.cart')
    this.loadBasketData(null)
  },
  methods: {
    loadBasketData (discountData) {
      var reqData = [];
      var shopCartIds = []
      if (discountData) {
        reqData.push(discountData);
        this.shopCatList.forEach(shopCart => {
          shopCart.shopCartItemDiscounts.forEach(cItems => {
            cItems.shopCartItems.forEach(pItem => {
              if (pItem.checked) {
                shopCartIds.push(pItem.basketId);
              }
            })
          })
        })
      }
      this.$axios.post('/p/shopCart/info', reqData).then(({ data }) => {

        var shopCatList = data
        console.log(data)
        if (data.length > 0) {
          if (shopCartIds.length == 0) {  // 初始加载
            this.shopCatList = shopCatList
          } else { // 修改购物车
            var checkedLog = []
            this.shopCatList.forEach(shopCart => {
              shopCart.shopCartItemDiscounts.forEach(shopCartItemDiscount => {
                shopCartItemDiscount.shopCartItems.forEach(shopCartItem => {
                  if (shopCartItem.checked) {
                    checkedLog.push(shopCartItem.basketId)
                  }
                })
              })
            })

            data.forEach(newShopCart => {
              newShopCart.shopCartItemDiscounts.forEach(newShopCartItemDiscount => {
                newShopCartItemDiscount.shopCartItems.forEach(shopCartItem => {
                  if (checkedLog.includes(shopCartItem.basketId)) {
                    shopCartItem.checked = true
                  }
                })
              });
            })
            this.shopCatList = data
          }
        } else {
          this.shopCatList = []
        }
        this.checkAllSelected()
        this.calTotalPrice(); //计算总价
      })
    },

    /**
     * 计算购物车总额
     */
    calTotalPrice () {
      var shopCatList = this.shopCatList;
      var shopCartIds = [];
      shopCatList.forEach(shopCart => {
        var shopCartItemDiscounts = shopCart.shopCartItemDiscounts;
        for (var i = 0; i < shopCartItemDiscounts.length; i++) {
          var cItems = shopCartItemDiscounts[i].shopCartItems;
          for (var j = 0; j < cItems.length; j++) {
            if (cItems[j].checked) {
              shopCartIds.push(cItems[j].basketId);
            }
          }
        }
      });
      this.$axios.post('/p/shopCart/totalPay', shopCartIds).then(({ data }) => {
        this.count = data.count
        this.finalMoney = data.finalMoney,
          this.totalMoney = data.totalMoney,
          this.subtractMoney = data.subtractMoney
      })
    },

    //收藏商品
    collection: _debounce(function(index, shopCartItemIndex, itemIndex) {
      const item = this.shopCatList[index].shopCartItemDiscounts[shopCartItemIndex].shopCartItems[itemIndex]
      var prodId = item.prodId
      this.$axios.get('/p/user/collection/isCollection', { params: { prodId } }).then(({ data }) => {
        if (data == true) {
          this.$message({
            message: this.$t('cart.theProductIsAlreadyInTheFavorites'),
            type: 'success',
            duration: 1000
          })
        } else {
          this.$axios.post('/p/user/collection/orderProdCollectionAll', item.prodId).then(({ data }) => {
            this.$message({
              message: this.$t('prodDetail.collectionSuccess'),
              type: 'success',
              duration: 1000
            })
            // item.isCollection = true
            return
          })
        }
      })
    },500),

    //打开弹窗
    openPopup (basketId) {
      this.isPopup = true
      this.basketId = basketId
    },
    //关闭弹窗
    closePopup () {
      this.isPopup = false
      this.basketId = null
    },
    //删除购物车商品
    remove () {
      var shopCartIds = []
      if (!this.basketId) {
        this.shopCatList.forEach(shop => {
          shop.shopCartItemDiscounts.forEach(item => {
            item.shopCartItems.forEach(shopCat => {
              if (shopCat.checked) {
                shopCartIds.push(shopCat.basketId);
              }
            });
          });
        });
      } else {
        shopCartIds.push(this.basketId)
      }
      if (!shopCartIds.length) {
        this.$message({
          type: 'warning',
          message: this.$t('cart.pleaseCheckTheItemsWantToDelete')
        })
        this.isPopup = false
        return
      }
      this.$axios.post('/p/shopCart/deleteItem', shopCartIds).then(({ data }) => {
        this.loadBasketData(null)
        this.getCartCount()
      })
      this.isPopup = false
    },

    /**
     * 每一项的选择事件
     */
    checkOne (index, shopCartItemIndex, itemIndex) {
      var shopCatList = this.shopCatList;
      var shopCartItemDiscounts = shopCatList[index].shopCartItemDiscounts; // 获取购物车列表
      var checked = shopCartItemDiscounts[shopCartItemIndex].shopCartItems[itemIndex].checked; // 获取当前商品的选中状态
      shopCartItemDiscounts[shopCartItemIndex].shopCartItems[itemIndex].checked = !checked; // 改变状态

      this.calTotalPrice(); // 计算总价
      this.checkAllSelected(); //检查全选状态
    },


    /**
     * 店铺勾选事件
     */
    checkShop (index, shopCartItemIndex) {
      this.shopCatList[index].checked = !this.shopCatList[index].checked
      var checked = this.shopCatList[index].checked
      this.shopCatList[index].shopCartItemDiscounts.forEach(item => {
        item.checked = checked
        item.shopCartItems.forEach(prodItem => {
          prodItem.checked = checked
        })
      })
      this.calTotalPrice()
      this.checkAllSelected()
    },
    /**
     * 全选事件
     */
    checkAll () {
      this.selectAll(this.shopCatList, !this.allChecked)
    },
    /**
     * 全选
     */
    selectAll () {
      var allChecked = this.allChecked;
      allChecked = !allChecked; //改变状态
      var shopCatList = this.shopCatList;
      shopCatList.forEach(shopCart => {
        shopCart.checked = allChecked;
        var shopCartItemDiscounts = shopCart.shopCartItemDiscounts;
        for (var i = 0; i < shopCartItemDiscounts.length; i++) {
          var cItems = shopCartItemDiscounts[i].shopCartItems;
          for (var j = 0; j < cItems.length; j++) {
            cItems[j].checked = allChecked;
          }
        }
      });
      this.allChecked = allChecked
      this.shopCatList = shopCatList
      this.calTotalPrice(); //计算总价
    },

    /**
     * 检查全选状态
     */
    checkAllSelected () {
      var allChecked = true;
      var shopCatList = this.shopCatList;
      var flag = false;
      shopCatList.forEach(shopCart => {
        var shopChecked = true;
        var shopCartItemDiscounts = shopCart.shopCartItemDiscounts;
        for (var i = 0; i < shopCartItemDiscounts.length; i++) {
          var cItems = shopCartItemDiscounts[i].shopCartItems;
          for (var j = 0; j < cItems.length; j++) {
            if (!cItems[j].checked) {
              shopChecked = false;
              allChecked = false;
              flag = true;
              break;
            }
          }
          if (flag) {
            break;
          }
        }
        shopCart.checked = shopChecked;
      });
      this.allChecked = allChecked
      this.shopCatList = shopCatList
    },

    /**
     * 减少数量
     */
    subCount (index, shopCartItemIndex, itemIndex) {
      var shopCatList = this.shopCatList;
      var shopCartItemDiscounts = shopCatList[index].shopCartItemDiscounts;
      var prodCount = shopCartItemDiscounts[shopCartItemIndex].shopCartItems[itemIndex].prodCount;
      if (prodCount > 1) {
        this.$nextTick(() => {
          this.updateCount(shopCatList, index, shopCartItemIndex, itemIndex, -1);
        })
      }
    },

    /**
     * 增加数量
     */
    addCount (index, shopCartItemIndex, itemIndex) {
      var shopCatList = this.shopCatList;
      var shopCartItemDiscounts = shopCatList[index].shopCartItemDiscounts;
      var prodCount = shopCartItemDiscounts[shopCartItemIndex].shopCartItems[itemIndex].prodCount;
      this.updateCount(shopCatList, index, shopCartItemIndex, itemIndex, 1);
    },

    /**
     * 改变购物车数量接口
     */
    updateCount: _debounce(function (shopCatList, index, shopCartItemIndex, itemIndex, changeProdCount) {
      var shopCartItemDiscounts = shopCatList[index].shopCartItemDiscounts;
      var prodCount = shopCatList[index].shopCartItemDiscounts[shopCartItemIndex].shopCartItems[itemIndex].prodCount;
      if (changeProdCount == -1 && prodCount == 1) {
        return
      }
      let sendData = {
        count: changeProdCount,
        prodId: shopCartItemDiscounts[shopCartItemIndex].shopCartItems[itemIndex].prodId,
        skuId: shopCartItemDiscounts[shopCartItemIndex].shopCartItems[itemIndex].skuId,
        shopId: shopCartItemDiscounts[shopCartItemIndex].shopCartItems[itemIndex].shopId
      }
      this.$axios.post('/p/shopCart/changeItem', sendData).then(({ data }) => {
        shopCartItemDiscounts[shopCartItemIndex].shopCartItems[itemIndex].prodCount += changeProdCount;
        this.shopCatList = shopCatList
        var discountData = {
          basketId: shopCartItemDiscounts[shopCartItemIndex].shopCartItems[itemIndex].basketId,
          discountId: shopCartItemDiscounts[shopCartItemIndex].shopCartItems[itemIndex].discountId
        }
        this.loadBasketData(discountData)
        this.getCartCount()
        if (changeProdCount > 0) {
          const flowAnalysisLogDto = JSON.parse(localStorage.getItem('flowAnalysisLogDto'))
          console.log(flowAnalysisLogDto)
          flowAnalysisLogDto.bizData = shopCartItemDiscounts[shopCartItemIndex].shopCartItems[itemIndex].prodId
          flowAnalysisLogDto.bizType = 0
          localStorage.setItem('flowAnalysisLogDto', JSON.stringify(flowAnalysisLogDto))
          util.tapLog(4, '', '', changeProdCount)
        }
      })
    }, 420),

    /**
     * 去结算
     */
    submit () {
      var shopCartIds = []
      this.shopCatList.forEach(shop => {
        shop.shopCartItemDiscounts.forEach(item => {
          item.shopCartItems.forEach(shopCat => {
            if (shopCat.checked) {
              shopCartIds.push(shopCat.basketId);
            }
          });
        });
      });
      if (shopCartIds.length < 1) {
        this.$message({
          message: this.$t('cart.pleaseSelectAtLeastOneItem'),
          type: 'error',
          duration: 1000
        })
        return
      }
      var basketIds = JSON.stringify(shopCartIds)
      sessionStorage.setItem('basketIds', basketIds);
      this.$router.push({ path: '/submit-order?orderEntry=0' })
    },
    /**
     * 价格处理
     */
    parsePrice: (value) => {
      var val = Number(value)
      if (!val) {
        val = 0;
      }
      // 截取小数点后两位，并以小数点为切割点将val转化为数组
      return val.toFixed(2).split(".");
    },

    /**
     * 修改促销活动
     */
    onChooseDiscount (discountId, basketId) {
      let obj = {
        basketId: basketId,
        discountId: discountId
      }
      this.discountData = obj
    },
    /**
     * 提交促销活动修改
     */
    submitDiscount () {
      var reqData = this.discountData
      this.loadBasketData(reqData)
      this.showDiscountsList = false
    },
    /**
     * 促销按钮
     */
    onShowDisList (val) {
      this.showDiscountsList = true
      this.currentBasketId = val
    },
    /**
     * 获取购物车商品总数
     */
    getCartCount () {
      this.$axios.get('/p/shopCart/prodCount').then(({ data }) => {
        this.$store.commit('cartNumber/changeCartNumber', data)
      })
    },
  }
}
</script>
<style scoped src='~/assets/css/cart.css'>
</style>

